import { Injectable } from '@angular/core';

import { User } from './user';

@Injectable({
  providedIn: 'root',
})
export class AuthService {
  currentUser: User | null;
  redirectUrl: string;

  constructor() {}

  get isLoggedIn() {
    return !!this.currentUser;
  }

  login(userName: string, password: string) {
    // Code here would log into a back end service
    // and return user information
    // This is just hard-coded here.
    this.currentUser = {
      id: 2,
      userName: userName,
      isAdmin: false,
    };
  }

  logout() {
    this.currentUser = null;
  }
}
